package com.jsh.mypor.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jsh.mypor.pojo.Student;
import com.jsh.mypor.pojo.Teacher;
import com.jsh.mypor.service.StudentService;
import com.jsh.mypor.util.MD5;
import com.jsh.mypor.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.print.Pageable;
import java.util.List;

@RestController
@RequestMapping("/sms/studentController")
public class StudentController {
    @Autowired
    private StudentService studentService;

    //http://localhost:9001/sms/studentController/addOrUpdateStudent
    @PostMapping("/addOrUpdateStudent")
    public Result addOrUpdateStudent(@RequestBody Student student){
        Integer id=student.getId();
        if (null==id||0==id){
            student.setPassword(MD5.encrypt(student.getPassword()));
        }
        studentService.saveOrUpdate(student);
        return Result.ok();
    }
    @DeleteMapping("/delStudentById")
    public Result delStudentById(
            @RequestBody List<Integer> ids){
        boolean b = studentService.removeByIds(ids);
        return Result.ok();
    }

    //http://localhost:9001/sms/studentController/getStudentByOpr/1/3?name=&clazzName
    @GetMapping("/getStudentByOpr/{pageNo}/{pageSize}")
    public Result getStudentByOpr(
            @PathVariable Integer pageNo,
            @PathVariable Integer pageSize,
           Student student
    ){
        Page<Student> page=new Page<>(pageNo,pageSize);
        IPage<Student> pageRS=studentService.getStudentByOpr(page,student);
        return Result.ok(pageRS);
    }
}
